/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
(function($){
    $.fn.extend({
        //plugin name - resizeimg
        resizeimg: function(options) {
            //Settings list and the default values
            var defaults = {
                maxWidth: 0,
                maxHeight:0
            };
            var options = $.extend(defaults, options);
            //            $.extend(defaults, options);
            
            return this.each(function() {
                var o = options;
                //Assign current element to variable, in this case is UL element
                var obj = $(this);   
                //Plugin code goes here
                var maxWidth = o.maxWidth;
                var maxHeight= o.maxHeight;
                
                var maxWidth = obj.parent().width();
                var maxHeight = obj.parent().height();
                
                var imgWidth = obj.width();
                var imgHeight = obj.height();
                
                var newHeight = maxHeight;
                var ratio = imgHeight/maxHeight;
                
                if(maxHeight > imgHeight){
                    ratio = maxHeight/imgHeight;
                }
                
                var newWidth = imgWidth/ratio;
                $(this).width(newWidth);
                $(this).height(newHeight);
                obj.css({
//                    'visibility':'visible',
                    'height': 'newHeight',
                    'width': 'newWidth'
                });
            });
        }
    });
})(jQuery);


//
//$(function myResize(){
//    // Define the space you have to work with
//    var maxWidth = 200;
//    var maxHeight = 700;
// 
//    $('.resizeme').hide().load(function(){ // Hide image and once it loads...
//        $(this).each(function(){ // Loop through each
//            var imgWidth = $(this).width();
//            var imgHeight = $(this).height();
//            // If image is landscape...
//            if(imgWidth > imgHeight) {
//                // Calculate proportionate height
//                var x = (imgHeight * maxWidth) / imgWidth;
//                $(this).width(maxWidth).height(x);
//            // If image is portrait...
//            } else if(imgWidth < imgHeight) {
//                // Calculate proportionate width
//                var x = (imgWidth * maxHeight) / imgHeight;
//                $(this).width(x).height(maxHeight);
//            // If image is perfectly square...
//            } else {
//                // AND if your space is landscape...
//                if(maxWidth > maxHeight) {
//                    // Assign maxHeight to both width and height
//                    $(this).width(maxHeight).height(maxHeight);
//                // AND if your space is portrait...
//                } else if(maxWidth < maxHeight) {
//                    // Assign maxWidth to both width and height
//                    $(this).width(maxWidth).height(maxWidth);
//                // AND if your space is perfectly square...
//                } else {
//                    // Assign respective dimensions
//                    $(this).width(maxWidth).height(maxHeight);
//                }
//            }
//            $(this).show(); // Show scaled image
//        });
//    });
//});
function myresize(){
    
}



function resizeBackground()
{
    
    var scale=0;
    var stageWidth=$(window).width();
    var newWidth=$(".resizeme").width();
    var stageHeight=$(window).height();
    var newHeight=$(".resizeme").height();

    if( $(window).width() > $(window).height() )
    {
        scale = stageHeight/newHeight;
        scale = stageWidth/newWidth;
    }
    else
    {
        scale = stageWidth/newWidth;
        scale = stageHeight/newHeight;
    }

    newWidth = newWidth*scale;
    newHeight = newHeight*scale;
    $(".resizeme").width(newWidth);
    $(".resizeme").height(newHeight);
}






//                if(imgWidth > imgHeight) {
//                    // Calculate proportionate height
//                    var x = (imgHeight * maxWidth) / imgWidth;
//                    $(this).width(maxWidth).height(x);
//                // If image is portrait...
//                } else if(imgWidth < imgHeight) {
//                    // Calculate proportionate width
//                    var x = (imgWidth * maxHeight) / imgHeight;
//                    $(this).width(x).height(maxHeight);
//                // If image is perfectly square...
//                } else{
//                    // AND if your space is landscape...
//                    if(maxWidth > maxHeight) {
//                        // Assign maxHeight to both width and height
//                        $(this).width(maxHeight).height(maxHeight);
//                    // AND if your space is portrait...
//                    } else if(maxWidth < maxHeight) {
//                        // Assign maxWidth to both width and height
//                        $(this).width(maxWidth).height(maxWidth);
//                    // AND if your space is perfectly square...
//                    } else {
//                        // Assign respective dimensions
//                        $(this).width(maxWidth).height(maxHeight);
//                    }
//                }